#include<bits/stdc++.h>
using namespace std;
int a[200005],b[200005];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin>>t;
    while(t--){
        int n,ans=0,Max=0;
        cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i];
        for(int i=0;i<(1<<n);i++){
            ans=0;
            for(int j=1;j<=n;j++)b[j]=0;
            for(int j=0;j<n;j++){
                if((i&(1<<j))==(1<<j))b[j+1]=1;
            }
            for(int j=2;j<=n;j++){
                for(int k=j-1;k>0;k--){
                    if(b[j]==b[k]){
                        if(a[j]==a[k])ans+=a[j];
                        k=-1;
                        break;
                    }
                }
            }
            Max=max(Max,ans);
        }
        cout<<Max<<endl;
    }
    return 0;
}
